<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>友情链接添加</title>
    <link rel="stylesheet" href="/static/public/layui/css/layui.css">
    <script type="text/javascript" src="/static/public/layui/layui.js"></script>
</head>
<body style="padding: 15px">
<form class="layui-form">
    @csrf
    <input type="hidden" name="id" value="{{ $item['id'] }}">
    <div class="layui-form-item">
        <label class="layui-form-label">链接名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" value="{{ $item['title'] }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="ord" value="{{ $item['ord'] }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">链接url</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="url" value="{{ $item['url']  }}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" title="禁用" lay-skin="primary" {{ $item['status'] ==0?'':'checked' }}>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" onclick="save()">保存</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    layui.use(['layer','form'],function(){
        layer = layui.layer;
        form = layui.form;
        $ = layui.jquery;
    });

    function save(){
        var title = $.trim($('input[name="title"]').val());
        var url = $.trim($('input[name="url"]').val());
        if(title==''){
            return layer.alert('链接名称不能为空',{icon:2});
        }
        if(url ==''){
            return layer.alert('链接url不能为空',{icon:2});
        }

        $.post('/admin/link/save',$('form').serialize(),function(res){
            if(res.code>0){
                return layer.alert(res.msg,{icon:2});
            }
            layer.msg(res.msg);
            setTimeout(function(){parent.window.location.reload();},1000);
        },'json');
    }
</script>

</body>
</html>
